package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.mchange.v1.identicator.IdList;
import com.mchange.v2.lang.ObjectUtils;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Course;
import com.ruoyi.system.domain.TeachingclassDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Teachingclass;
import com.ruoyi.system.service.ITeachingclassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级管理Controller
 * 
 * @author ruoyi
 * @date 2023-07-20
 */
@Api(tags="班级信息管理")
@RestController
@RequestMapping("/system/teachingclass")
public class TeachingclassController extends BaseController
{
    @Autowired
    private ITeachingclassService teachingclassService;
    /**
     * 查询班级管理列表
     */
    @Anonymous
//    @ApiOperation("获取班级列表")
    @GetMapping("/listBy2")
    public AjaxResult listBy2(Teachingclass teachingclass)
    {
        teachingclass.setDeptId(SecurityUtils.getDeptId());
        startPage();
        List<Teachingclass> list = teachingclassService.selectTeachingclassList(teachingclass);
        List<TeachingclassDTO> dto = new ArrayList<>();
        for(Teachingclass item:list){
            TeachingclassDTO object = new TeachingclassDTO();
            BeanUtils.copyProperties(item,object);
            object.setContent(JSON.parse(item.getContent()));
            dto.add(object);
        }
        return success(dto);
    }
    /**
     * 查询班级管理列表
     */
    @Anonymous
    @ApiOperation("获取班级列表")
    @GetMapping("/listBy")
    public TableDataInfo listBy(Long deptId)
    {
//        teachingclass.setDeptId(SecurityUtils.getDeptId());
        startPage();
        Teachingclass teachingclass = new Teachingclass();
        teachingclass.setDeptId(deptId);
        List<Teachingclass> list = teachingclassService.selectTeachingclassList(teachingclass);
        List<TeachingclassDTO> dto = new ArrayList<>();
        for(Teachingclass item:list){
            TeachingclassDTO object = new TeachingclassDTO();
            BeanUtils.copyProperties(item,object);
            object.setContent(JSON.parse(item.getContent()));
            dto.add(object);
        }
        return getDataTable(dto);
    }
    /**
     * 查询班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:teachingclass:list')")
    @GetMapping("/list")
    public TableDataInfo list(Teachingclass teachingclass)
    {
        teachingclass.setDeptId(SecurityUtils.getDeptId());
        startPage();
        List<Teachingclass> list = teachingclassService.selectTeachingclassList(teachingclass);
        List<TeachingclassDTO> dto = new ArrayList<>();
        for(Teachingclass item:list){
            TeachingclassDTO object = new TeachingclassDTO();
            BeanUtils.copyProperties(item,object);
            object.setContent(JSON.parse(item.getContent()));
            dto.add(object);
        }
        return getDataTable(dto);
    }

    /**
     * 获取班级管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teachingclass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        TeachingclassDTO dto = new TeachingclassDTO();
        Teachingclass item = teachingclassService.selectTeachingclassById(id);
        BeanUtils.copyProperties(item,dto);
        dto.setContent(JSON.parse(item.getContent()));
        return success(dto);
    }

    /**
     * 新增班级管理
     */
    @PreAuthorize("@ss.hasPermi('system:teachingclass:add')")
    @Log(title = "班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Teachingclass teachingclass)
    {
        teachingclass.setDeptId(SecurityUtils.getDeptId());
        return toAjax(teachingclassService.insertTeachingclass(teachingclass));
    }

    /**
     * 修改班级管理
     */
    @PreAuthorize("@ss.hasPermi('system:teachingclass:edit')")
    @Log(title = "班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Teachingclass teachingclass)
    {
        teachingclass.setDeptId(SecurityUtils.getDeptId());
        return toAjax(teachingclassService.updateTeachingclass(teachingclass));
    }

    /**
     * 删除班级管理
     */
    @PreAuthorize("@ss.hasPermi('system:teachingclass:remove')")
    @Log(title = "班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teachingclassService.deleteTeachingclassByIds(ids));
    }
}
